<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0, shrink-to-fit=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <title>在线学习报名系统</title>

    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="/assets/vue.js"></script>
    <script src="/assets/axios.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/assets/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="/assets/element-ui/lib/index.js"></script>
    <script src="/assets/js/api.js"></script>
</head>

<body>
    <div id="app">
        <div class="s-header">
            在线学习报名系统
        </div>
        <div class="s-body">
            <el-form :model="userInfo" label-width="80px" style="width: 500px;margin: 0 auto;margin-top: 200px">
                <el-form-item label="邮箱">
                    <el-input v-model="userInfo.email"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input type="password" v-model="userInfo.password"></el-input>
                </el-form-item>
                <p style="text-align: center" >
                    <el-button type="primary" @click="login()">登录</el-button>
                </p>
            </el-form>
        </div>
    </div>
</body>

<script>
    var app = new Vue({
        el: "#app",
        data: {
            userInfo: {}
        },
        mounted() {
            this.checkLogin()
        },
        methods: {
            checkLogin() {
                window.api.post('/api/checkLogin').then(function (response) {
                    if (response.data) {
                        window.location.href = '/home';
                    }
                })
            },
            login() {
                window.api.post('/api/login', this.userInfo).then(res => {
                    if (res.code == 200) {
                        localStorage.setItem('token', res.data.token)
                        this.$message.success('登录成功');
                        window.location.href = '/home';
                    } else {
                        this.$message.error(res.message);
                    }
                })
            }
        },
        computed: {
        }
    })
</script>

<style>
    body {
        margin: 0;
        background: #f5f7fa;

    }
    .s-header {
        background: #0d6aad;
        height: 100px;
        line-height: 100px;
        padding-left: 20px;
        font-size: 50px;
        color: white;
    }
    .s-body {
        background: #f5f7fa;
        padding: 10px;
        height: 100%;
    }
</style>

</html>
